<html xmlns="http://www.w3.org/1999/xhtml" >
<%@ page language="java" import	="java.io.*,java.sql.*" %>

<%@include file="../dbcon.jsp"%>
<%
	int iMsgId = 1; 
	int iSno = 0;
	int iRecType = 0;
	
String sName = "",sTitle = "",sAddress = "",sNationalid = "", sNISno = "", sPlaceofemploymentno="";
	String sNoofconviction = "", sDateofconviction = "", sMobile = "", sEmail = "", sLandline = "", sDesc = "", sDetailsofconviction = "";
	int iLandType = 0;
			
	String sTmp = request.getParameter("hid_RecType");
	if ( sTmp != null && !sTmp.equals("null") && !sTmp.equals("") )
		iRecType = Integer.parseInt(sTmp);
	
	sTmp = request.getParameter("hid_RecSno");
	if ( sTmp != null && !sTmp.equals("null") && !sTmp.equals("") )
		iSno = Integer.parseInt(sTmp);
//System.out.println("iSno : "+ iSno);			
	if ( sTmp == null || sTmp.equals("null") || sTmp.equals("") )
	{
		response.sendRedirect("frm_usedcar.jsp");
		//System.out.println("sTmp : "+ sTmp);				
		return;
	}
	
	
	sTitle = request.getParameter("txt_title");
	sName = request.getParameter("txt_name");	
	sAddress = request.getParameter("txt_address");	
	sNationalid = request.getParameter("txt_nationalid");
	sNISno = request.getParameter("txt_NISno");
	sPlaceofemploymentno = request.getParameter("txt_placeofempno");
	sNoofconviction = request.getParameter("txt_noofconviction");
	sDateofconviction = request.getParameter("txt_dateofconviction");
	sDetailsofconviction = request.getParameter("txt_detailsofconviction");
	sMobile = request.getParameter("txt_mobile");
	sLandline = request.getParameter("txt_landline");	
	sEmail = request.getParameter("txt_email");
	sDesc = request.getParameter("ta_desc");
	
	
			
	
	try{		
		String sRtnMsg = "";
		if ( iRecType == 1 )
		{
			String sQry = "insert into tbl_persons(name,address,national_id,";
			sQry += "NIS, places_emt, noof_convictions, convictions_date,";
			sQry += "convictions_details,title,mobile ,landline ,email ) values(";
			sQry +=  sName +"','"+ sAddress +"',";
			sQry += "'"+ sNationalid +"','"+ sNISno +"',"+ sPlaceofemploymentno ;
			sQry += ",'"+ sNoofconviction +"','" + sDateofconviction +"','"+ sDetailsofconviction +"','";
			sQry += "'"+ sTitle +"'";
			sQry += ",'"+ sMobile +"','" + sLandline +"','"+ sEmail +"'";
			sQry += ")";
			
		System.out.println("tbl_persons Qry : "+ sQry);					

			Statement Stmt = Con.createStatement();
			Stmt.executeUpdate(sQry);
			if ( Stmt != null ) Stmt.close();

			iMsgId = 1;
			System.out.println("Insert Successfully");
		}
		else if ( iRecType == 2)
		{
			String sQry = "update tbl_persons set ";
			sQry += "name='"+ sName +"',";
			sQry += "address='"+ sAddress +"',";
			sQry += "national_id='"+ sNationalid +"',";			
			sQry += "NIS='"+ sNISno +"',";			
			sQry += "places_emt='"+ sPlaceofemploymentno +"',";
			sQry += "noof_convictions='"+ sNoofconviction +"',";
			sQry += "convictions_date='"+ sDateofconviction +"',";
			sQry += "convictions_details='"+ sDetailsofconviction +"',";
			sQry += "title='"+ sTitle +"',";
			sQry += " where id="+ iSno;
		System.out.println("tbl_persons Qry : "+ sQry);					
		
			Statement Stmt = Con.createStatement();
			Stmt.executeUpdate(sQry);
			if ( Stmt != null ) Stmt.close();
					
			iMsgId = 3;
			System.out.println("Update Successfully");
		}
	}
	catch(Exception e)
	{	
		System.out.println("Failed : "+ e);	
		if ( iRecType == 1 ) iMsgId = 2;
		else iMsgId = 4;
	}
	
	if ( Con != null ) Con.close();
	response.sendRedirect("../frm_msg.jsp?MsgID="+ iMsgId);
	//System.out.println("Insert Failed");
%>
</html>